<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>菜品管理</title>
<style>

  * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }

 .img_c{
    height: 250px;
    width: 250px;
    
  }

  body {
    font-family: Arial, sans-serif; /* 设置字体 */
    background-color: #f8f8f8; /* 设置背景色 */
  }

  .container {
    width: 80%;
    margin: auto; /* 使容器居中 */
    padding: 20px;
  }

  h1, h2 {
    color: #333; /* 设置标题颜色 */
    text-align: center; /* 标题居中 */
    margin-bottom: 20px;
  }

  .menu-item {
    background-color: #fff; /* 设置菜品项的背景色 */
    padding: 20px;
    margin-bottom: 20px;
    border-radius: 5px; /* 边框圆角效果 */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); /* 盒子阴影效果 */
  }

  .menu-item img {
    width: 100%; /* 图片宽度撑满容器 */
    height: auto; /* 图片高度自动 */
    margin-bottom: 10px;
  }

  .menu-item h3 {
    margin-bottom: 10px;
  }

  .menu-item p {
    margin-bottom: 10px;
  }

  .add-to-cart {
    display: inline-block; /* 将按钮显示为内联块级元素 */
    background-color: #008CBA; /* 设置按钮背景色 */
    color: white; /* 设置按钮文字颜色 */
    padding: 10px 20px;
    text-decoration: none; /* 移除下划线 */
    border-radius: 5px; /* 按钮边框圆角效果 */
    transition: background-color 0.3s; /* 添加背景颜色过渡效果 */
  }
  
  a{
    display: inline-block; /* 将按钮显示为内联块级元素 */
    background-color: #008CBA; /* 设置按钮背景色 */
    color: white; /* 设置按钮文字颜色 */
    padding: 10px 20px;
    text-decoration: none; /* 移除下划线 */
    border-radius: 5px; /* 按钮边框圆角效果 */
    transition: background-color 0.3s; /* 添加背景颜色过渡效果 */
  }

  .add-to-cart:hover {
    background-color: #005f73; /* 鼠标悬停时的按钮背景色 */
  }

  /* 购物车样式 */
  #cart {
    background-color: #fff;
    padding: 20px;
    margin-top: 20px;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  }

  #cart-items li {
    list-style-type: none; /* 移除列表项目符号 */
    margin-bottom: 10px;
  }

  #total-price {
    font-weight: bold; /* 总价字体加粗 */
  }
  
        /* 小屏设备（手机）样式 */
@media (max-width: 600px) {
    .container {
        width: 95%;
        padding: 10px;
    }
    .menu-item {
        padding: 5px;
    }
    .menu-item img {
        height: 150px;
    }
    .menu-item h3 {
        font-size: 1.2em;
    }
    .menu-item p {
        font-size: 0.9em;
    }
    .menu-item button {
        padding: 5px 10px;
        font-size: 0.9em;
    }
    #cart {
        padding: 10px;
    }
    #cart h2 {
        font-size: 1.2em;
    }
    #cart-items li {
        font-size: 0.9em;
    }
    #checkout-btn {
        padding: 5px 10px;
        font-size: 0.9em;
    }
}

/* 中等屏幕（平板）样式 */
@media (min-width: 601px) and (max-width: 1024px) {
    .container {
        width: 85%;
    }
    .menu-item img {
        height: 180px;
    }
}

/* 大屏设备（桌面）样式 */
@media (min-width: 1025px) {
    .container {
        width: 70%;
    }
    .menu-item img {
        height: 200px;
    }
}
    </style>
</head>
<body>
<%	
    String customer_name = request.getParameter("customer_name");
    String restaurant_name = request.getParameter("restaurant_name");
    System.out.print(restaurant_name);
%>
<div class="container">
    <h1><%=restaurant_name%>的菜品列表</h1>
    <h2>欢迎用户:<%=customer_name%></h2>

    <%
    Connection conn = DriverManager.getConnection("jdbc:mariadb://localhost:3306/mealdb?user=root&password=1230321");
    Statement stmt = conn.createStatement();
        String sql ="select * from meal_detail ";
        ResultSet rs = stmt.executeQuery(sql);
        while (rs.next()){
            String name = rs.getString("name");
            String img = rs.getString("img");
            String state = rs.getString("state");
            String price = rs.getString("price");
            String active = rs.getString("active");
    %>
    <div class="menu-item">
        <div class='img_c'><img src="<%=img%>" alt="菜品图片"></div>
        <h3><%=name%></h3>
        <p><%=state%></p>
        <p>价格: <%=price%></p>
        <h2>余量: <%=active%></h2>
        <a class="add-to-cart" href='addUpMeal.jsp?customer_name=<%=customer_name%>&meal_name=<%=name%>&restaurant_name=<%=restaurant_name%>'>上架</a>
        <a class="add-to-cart" href='soldOutDish.jsp?meal_name=<%=name%>&customer_name=<%=customer_name%>&restaurant_name=<%=restaurant_name%>'>下架</a>
    </div>
    <%}
        rs.close();
        stmt.close();
        conn.close();%>
</div>
</body>
</html>